\section{Source/String.h}


\begin{footnotesize}\begin{alltt}
00001 
00015 \textcolor{preprocessor}{#ifndef STRING\_HEADER}
00016 \textcolor{preprocessor}{}\textcolor{preprocessor}{#define STRING\_HEADER}
00017 \textcolor{preprocessor}{}
00018 \textcolor{preprocessor}{#include <stdio.h>}
00019 \textcolor{preprocessor}{#include <stdlib.h>}
00020 \textcolor{preprocessor}{#include <string.h>}
00021 \textcolor{preprocessor}{#include <ctype.h>}
00022 
00023 \textcolor{comment}{/* NOTE:}
00024 \textcolor{comment}{ *  The functions with Safe appended are the functions that should be used}
00025 \textcolor{comment}{ *  if the string may contain null bytes}
00026 \textcolor{comment}{ *  }
00027 \textcolor{comment}{ *  The functions with S appended are functions that work on another instantiatio
      n of}
00028 \textcolor{comment}{ *  this implementation, rather than char arrays}
00029 \textcolor{comment}{ */}
00030 
00035 \textcolor{keyword}{typedef} \textcolor{keyword}{struct}
00036 \{
00037     \textcolor{keywordtype}{char} *String; 
00038     \textcolor{keywordtype}{int} Length; 
00039     \textcolor{keywordtype}{int} Size;   
00040 \}S_String;
00041 
00043 \textcolor{preprocessor}{#define S\_GetCString(Str)           (((char *)((S\_String *)Str)->String))}
00044 \textcolor{preprocessor}{}
00045 \textcolor{preprocessor}{#define S\_GetStringLength(String)   ((((S\_String*)Str)->Length))}
00046 \textcolor{preprocessor}{}
00049 \textcolor{preprocessor}{#define S\_Print(Str)                (printf("%s", (((S\_String *)Str)->String)))}
00050 \textcolor{preprocessor}{}
00051 \textcolor{preprocessor}{#define S\_GetSize(Str)              (((S\_String *)Str)->Size)}
00052 \textcolor{preprocessor}{}
00053 \textcolor{preprocessor}{#define S\_At(Str, At)               (char)(((S\_String *)Str)->String[At])}
00054 \textcolor{preprocessor}{}
00055 \textcolor{preprocessor}{#define S\_Capitalise(Str)           do\{if(((S\_String *)Str)->Length>0&&islower(((
      S\_String *)Str)->String[0]))\(\backslash\)}
00056 \textcolor{preprocessor}{                                    \{((S\_String *)Str)->String[0]=toupper(((S\_Str
      ing *)Str)->String[0]);\}\}while(0)}
00057 \textcolor{preprocessor}{}
00065 S_String *S\_NewString(\textcolor{keywordtype}{char} *String);
00075 S_String *S\_NewStringSafe(\textcolor{keywordtype}{char} *String, \textcolor{keywordtype}{int} Length);
00076 
00084 \textcolor{keywordtype}{void} S\_FreeString(S_String *String);
00085 
00097 \textcolor{keywordtype}{int} S\_SetString(S_String *String, \textcolor{keywordtype}{char} *Str);
00109 \textcolor{keywordtype}{int} S\_SetStringS(S_String *String, S_String *SetString);
00124 \textcolor{keywordtype}{int} S\_SetStringSafe(S_String *String, \textcolor{keywordtype}{char} *Str, \textcolor{keywordtype}{int} Length);
00125 
00138 \textcolor{keywordtype}{int} S\_AppendString(S_String *String, \textcolor{keywordtype}{char} *Str);
00151 \textcolor{keywordtype}{int} S\_AppendStringS(S_String *Str, S_String *AppendString);
00166 \textcolor{keywordtype}{int} S\_AppendStringSafe(S_String *String, \textcolor{keywordtype}{char} *Str, \textcolor{keywordtype}{int} Length);
00167 
00185 \textcolor{keywordtype}{int} S\_InsertString(S_String *String, \textcolor{keywordtype}{int} Offset, \textcolor{keywordtype}{char} *Str);
00199 \textcolor{keywordtype}{int} S\_InsertStringS(S_String *Str, \textcolor{keywordtype}{int} Offset, S_String *InsertString);
00216 \textcolor{keywordtype}{int} S\_InsertStringSafe(S_String *String, \textcolor{keywordtype}{int} Offset, \textcolor{keywordtype}{char} *Str, \textcolor{keywordtype}{int} Length);
00217 
00223 \textcolor{keywordtype}{void} S\_PrintSafe(S_String *String);
00235 \textcolor{keywordtype}{int} S\_PrependString(S_String *String, \textcolor{keywordtype}{char} *Str);
00247 \textcolor{keywordtype}{int} S\_PrependStringS(S_String *String, S_String *PString);
00262 \textcolor{keywordtype}{int} S\_PrependStringSafe(S_String *String, \textcolor{keywordtype}{char} *Str, \textcolor{keywordtype}{int} Length);
00263 
00264 \textcolor{comment}{/* Original comment documentation here, new doxygen comment underneath */}
00265 \textcolor{comment}{/* This function will set how many bytes are currently allocated for the string.}
00266 \textcolor{comment}{    NOTE:   }
00267 \textcolor{comment}{        The bytes may be allocated but it does not mean they are being used.}
00268 \textcolor{comment}{    }
00269 \textcolor{comment}{        It is not neccesary to call this function before using a function which w
      ill}
00270 \textcolor{comment}{        increase the size of the string, this library will take care of that for 
      you}
00271 \textcolor{comment}{*/}
00283 \textcolor{keywordtype}{int} S\_SetSize(S_String *String, \textcolor{keywordtype}{int} Size);
00284 
00285 \textcolor{comment}{/* This function will return the memory that is residing at the S\_String->String 
      offset of At}
00286 \textcolor{comment}{    NOTE:}
00287 \textcolor{comment}{        This function will not check to see if memory bounds are being crossed. T
      his is not}
00288 \textcolor{comment}{        laziness, this is a design choice because there would be no (nice, thread
      -friendly, re-entrant)}
00289 \textcolor{comment}{        way to return on error IMO. If anybody has any ideas, feel free to share}
00290 \textcolor{comment}{*/}
00291 \textcolor{comment}{//char S\_At(S\_String *String, int At); This function is now a macro}
00292 
00293 \textcolor{comment}{/* Original comment documentation here, new doxygen comment underneath */} \textcolor{comment}{/* TODO
      OOOOOOOO Doxygen comments... (and the actual functions) */}
00294 \textcolor{comment}{/* These functions will find first and last occurances of chars, strings or S\_Str
      ings.}
00295 \textcolor{comment}{    Functions appended with C work on chars}
00296 \textcolor{comment}{    Functions appended with S work on S\_Strings}
00297 \textcolor{comment}{    Functions appended with nothing work on char arrays}
00298 \textcolor{comment}{    Functions appended with safe work on char arrays with given lengths.}
00299 \textcolor{comment}{    }
00300 \textcolor{comment}{    Functions which have FindFirst in their name find the first occurance of }
00301 \textcolor{comment}{    entities, and expectedly FindLast finds the last occurance}
00302 \textcolor{comment}{    }
00303 \textcolor{comment}{    When no occurance is found, these functions return -1, and on success they re
      turn the offset}
00304 \textcolor{comment}{*/}
00305 \textcolor{keywordtype}{int} S\_FindFirstC(S_String *String, \textcolor{keywordtype}{char} Search);
00306 \textcolor{keywordtype}{int} S\_FindLastC(S_String *String, \textcolor{keywordtype}{char} Search);
00307 \textcolor{keywordtype}{int} S\_FindFirst(S_String *String, \textcolor{keywordtype}{char} *Search);
00308 \textcolor{keywordtype}{int} S\_FindLast(S_String *String, \textcolor{keywordtype}{char} *Search);
00309 \textcolor{keywordtype}{int} S\_FindFirstS(S_String *String, S_String *Search);
00310 \textcolor{keywordtype}{int} S\_FindLastS(S_String *String, S_String *Search);
00311 \textcolor{keywordtype}{int} S\_FindFirstSafe(S_String *String, \textcolor{keywordtype}{char} *Search, \textcolor{keywordtype}{int} Length);
00312 \textcolor{keywordtype}{int} S\_FindLastSafe(S_String *String, \textcolor{keywordtype}{char} *Search, \textcolor{keywordtype}{int} Length);
00313 
00321 \textcolor{keywordtype}{void} S\_StringReverse(S_String *String);
00329 \textcolor{keywordtype}{void} S\_ToUpper(S_String *String);
00338 \textcolor{keywordtype}{void} S\_Strip(S_String *String);
00352 \textcolor{keywordtype}{int} S\_PadFront(S_String *Str, \textcolor{keywordtype}{int} Length, \textcolor{keywordtype}{char} PadChar);
00372 \textcolor{keywordtype}{int} S_ToInt(S_String *String);
00392 \textcolor{keywordtype}{long} S_ToLong(S_String *String);
00393 
00394 \textcolor{preprocessor}{#endif}
\end{alltt}\end{footnotesize}
